<?php
/**
 * Shows the popups
 *
 *
 * LICENSE: Some license information
 *
  phpMMB version: 0.0.1
 
  $copyright  2007 SaWey
  $license    GNU GPL v3.
  $URL: http://www.sawey.be/phpMyMovieBox $
  $Revision: 6 $
  $LastChangedBy: sander.weyens $
  $Date: 2008-01-14 22:20:38 +0000 (Mon, 14 Jan 2008) $
*/

$movie_id = (int)$_GET['movie'];

$tpl->define(array('popup' => "popup.htm"));
$tpl->assign('TITLE', $config['site_title']);

//get movie info
$movie = get_movie_info($movie_id);
$colspan += 4;

//build genre_icon array
$genre_icons_translated = '';
foreach($lang_genre as $english => $translated)
{
	$genre_icons_translated[$translated] = $genre_icons[$english];
}
//create genres
$genres = '';
if(is_array($movie['genres']))
{
	foreach($movie['genres'] as $genre)
	{	
		if($config['genre_icons'] == 1)
		{
			$genres .= '<a href="?page=search&genre=' . $genre . '" target="_blank"><img alt="' . $genre . '" border="0" src="' . $genre_icons_translated[$genre] . '" /></a> | ';
		}
		else
		{
			$genres .= '<a href="?page=search&genre=' . $genre . '" target="_blank">' . $genre . '</a> | ';
		}
	}
	$genres = substr($genres, 0, (strlen($genres) - 3) );
}

$tpl->assign(array(
				'RES_POSTER'	=> $movie['main']['poster'],
				'RES_TITLE'		=> $movie['main']['title'],
				'RES_GENRE'		=> $genres,
				'RES_YEAR'		=> $movie['main']['year'],
				'RES_TAGLINE'	=> $movie['main']['tagline'],
				'RES_PLOT'		=> $movie['main']['plot'],
				'RES_COUNTRY'	=> $movie['main']['country'],
				'RES_COLOR'		=> $movie['main']['color'],
				'RES_IMDB_RATING'=> $movie['main']['imdb_rating'],
				'RES_PERSONAL_RATING'=> $movie['main']['personal_rating'],
				'RES_IMDB_ID'	=> $movie['main']['imdb_id'],
			));

$tpl->define_dynamic('movie_info_aka', 'popup');
if($movie['main']['aka'] != '')
{
	$tpl->assign(array('RES_AKA'		=> $movie['main']['aka']));
	$tpl->parse('MOVIE_INFO_AKA', '.movie_info_aka');
	$colspan += 1;
}

//parse directors
$tpl_tags = array(
	'RES_DIRECTOR'	=> 'name'
);
parse_movie_item_on_template($movie['people']['d'], 'movie_info_director', $tpl_tags);

//parse cast
$tpl_tags = array(
	'RES_CAST'	=> 'name',
	'RES_CAST_AS'	=> 'character',
);
parse_movie_item_on_template($movie['people']['a'], 'movie_info_cast', $tpl_tags);

//parse writers
$tpl_tags = array(
	'RES_WRITER'	=> 'name'
);
parse_movie_item_on_template($movie['people']['w'], 'movie_info_writer', $tpl_tags);

//parse languages
$tpl_tags = array(
	'RES_LANGUAGE'	=> 'numeric'
);
parse_movie_item_on_template($movie['languages'], 'movie_info_language', $tpl_tags);

//parse genres
$tpl_tags = array(
	'RES_AWARDS'	=> 'numeric'
);
parse_movie_item_on_template($movie['awards'], 'movie_info_awards', $tpl_tags);		

$tpl->assign(array('COLSPAN' => $colspan));

function parse_movie_item_on_template($movie_item, $tpl_item, $tpl_tags, $tpl_parent = 'popup')
{
	global $tpl;
	if(is_array($movie_item))
	{
		$tpl->define_dynamic($tpl_item, $tpl_parent);
		foreach($movie_item as $parsable)
		{
			$assign_arr = '';
			foreach($tpl_tags as $tag => $movie_item_key)
			{
				if($movie_item_key == 'numeric')
				{
					$assign_arr[$tag] = $parsable;
				}
				else
				{
					$assign_arr[$tag] = $parsable[$movie_item_key];
				}
			}
			
			$tpl->assign($assign_arr);
			$tpl->parse(strtoupper($tpl_item), '.' . $tpl_item);
		}
	}
}


























$tpl->parse('PAGE', "popup");
$tpl->FastPrint("PAGE");
exit;
?>